﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Sockets;
namespace SessionDemo
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            Session["Username"] = txtUsername.Text;
            Session["Password"] = txtPassword.Text;
            Session["Fullname"] = txtRealname.Text;
            Session["TimeOnline"] = DateTime.Now.ToLongTimeString() + " , " + DateTime.Now.ToLongDateString();
            Session["ClientIP"] = GetLocalIPAddress();
            Response.Redirect("Home.aspx");
        }

        private string GetUserIP()
        {
            string clientIP = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.GetValue(0).ToString();
            //string clientIP = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim();
            return clientIP;
        }
        public string GetLocalIPAddress()
        {
            IPHostEntry host;
            string localIP = "";
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    localIP = ip.ToString();
                    break;
                }
            }
            return localIP;
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Page.FindControl
        }
    }
}